<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>php make page list</title>
</head>
<body style="background: url('img/14806952[1].jpg');background-size:100%">
<div style="width: 700px;margin: 0 auto">
<table width="800">
    <tr>
        <td width="200" bgcolor="#E0EEE0" align="center">公告标题</td>
        <td width="400" bgcolor="#E0EEE0" align="center">公告内容</td>
        <td width="100" bgcolor="#E0EEE0" align="center">公告人</td>
        <td width="100" bgcolor="#E0EEE0" align="center">发布时间</td>
    </tr>
<?php
$conn = mysqli_connect("localhost","root","","abcd");
if (!$conn){
    die("连接数据库失败：" . mysqli_error());
}
header("Content-type:text/html;charset=utf-8");
$sql="select * from gonggao";
$sql=mysqli_query($conn,$sql);
while ($row=mysqli_fetch_array($sql)) {
    ?>
    <tr>
        <td bgcolor="#E0EEE0" height="80" width="200"><div align="center">
                <?php echo $row['title']?>
            </div></td>
        <td bgcolor="#E0EEE" width="400"><div align="center">
                <?php echo $row['content']?>
            </div></td>
        <td bgcolor="#E0EEE" width="100"><div align="center">
                <?php echo $row['host']?>
            </div></td>
        <td bgcolor="#ff7c8d" align="center"><a href="chakangonggao.php?id=<?php echo $row['cid']; ?>" name="shanchu">
        <?php
        echo $row['times'];
        @session_start();
        $user=$_SESSION['username'];
        $sqlT=mysqli_query($conn,"select * from user WHERE username='$user'");
        $rowT=mysqli_fetch_array($sqlT);
        if($user=='che'){
            echo "<br/><span style='color: #000'>删除</span>";
        }
        elseif($rowT['cengji']==1 && $user==$row['host'])
        {
            echo "<br/><span style='color: #000'>删除</span>";
        }
        ?>
        </td>
    </tr>
    <?php
}?>
</table>
</div>
</body>
</html>
<?php
if(isset($_GET['id']))
{
    if($rowT['cengji']==1){
        $a=$_GET['id'];
        $delete="delete from gonggao WHERE cid=$a";
        mysqli_query($conn,$delete);
        echo "<script language='javascript'>location.href='chakangonggao.php';</script>";
    }
}
?>